<!DOCTYPE html>
<?php
error_reporting(0);
session_start();
if(!isset($_SESSION['isLogin']) || !$_SESSION['isLogin'])
{
	header("location:/login.php");exit;
}
$current_plate_number_id = isset($_GET['plate_number'])?$_GET['plate_number']:1; 
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
    </style>
    <title>GPS</title>
    <link href="/css/bootstrap.css" rel="stylesheet">
</head>
<body>
    <div id="allmap"></div>
</body>
</html>
<script src="/js/jquery.js"></script>
<script type="text/javascript">
    // 百度地图API功能
    window.onload = loadJScript;  //异步加载地图
    countSecond();
    function countSecond()
    {
        loadJScript();
     　 setTimeout("countSecond()", 5000)
    }
    
    function loadJScript() {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://api.map.baidu.com/api?v=2.0&ak=lD7q01aWvUlwbFfHHQqtdVGNd9cxxK9O&callback=init";
        document.body.appendChild(script);
    }
    function init() {	
        //var map = new BMap.Map("allmap");            // 创建Map实例
        $.post("/long_lat.php",{id:"<?php echo $current_plate_number_id?>"},function(data){
            $('#speed', window.parent.document).html(data.speed);//更新速度
            $('#time', window.parent.document).html(data.gps_time);//更新速度
			
            var x = data.Long;
            var y = data.Lati;
            x = parseInt(x/100)+(x-(parseInt(x/100))*100)/60;
            y = parseInt(y/100)+(y-(parseInt(y/100))*100)/60;
		
			var ggPoint = new BMap.Point(x,y);
			var bm = new BMap.Map("allmap");
			bm.centerAndZoom(ggPoint, 15);
			bm.addControl(new BMap.NavigationControl());
			translateCallback = function (data){
			  if(data.status === 0) {
				var marker = new BMap.Marker(data.points[0]);
				bm.addOverlay(marker);
				
				bm.setCenter(data.points[0]);
				$('#long', window.parent.document).html("维度："+data.points[0].lng);//更新经度
				$('#lati', window.parent.document).html("经度："+data.points[0].lat);//更新维度
			  }
			}
			var convertor = new BMap.Convertor();
			var pointArr = [];
			pointArr.push(ggPoint);
			convertor.translate(pointArr, 1, 5, translateCallback)
				
				
			},"json");
    }  
	

  
</script>
